package com.stars.empoly.adapter

import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.empoly.R
import com.stars.empoly.activity.*
import com.stars.empoly.databinding.ItemAddressListBinding
import com.stars.empoly.databinding.ItemBuyChoseBinding
import com.stars.empoly.databinding.ItemHeartBinding
import com.stars.empoly.databinding.ItemMsgBinding
import com.stars.empoly.inte.ChoiceData
import com.stars.empoly.model.FollowList
import com.stars.empoly.model.MsgList
import com.stars.empoly.model.ServiceList
import com.stars.empoly.model.TrMsgList
import com.stars.empoly.vmodel.AddressListVModel
import com.stars.empoly.vmodel.HeartVModel
import com.stars.empoly.vmodel.MsgVModel
import com.trailer.base.base.BAdapter
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch

class PopuBuyAdapter(var choseData: ChoiceData) : BAdapter<ServiceList.ContentBean, BaseDataBindingHolder<ItemBuyChoseBinding>>(R.layout.item_buy_chose) {

    override fun convert(holder: BaseDataBindingHolder<ItemBuyChoseBinding>, item: ServiceList.ContentBean) {
        holder.dataBinding?.item = item


        holder.dataBinding?.imgReduce?.onClick {
            //减少
            var num=holder.dataBinding?.tv?.text.toString().toInt()
            if(num==0){
                return@onClick
            }
            var i=num-1
            holder.dataBinding?.tv?.text=""+i
            item.choseNumber=""+i
            if(i==0){
                holder.dataBinding?.imgAdd?.setImageResource(R.drawable.me_add)
            }
            if(null!=choseData){
                choseData.onRestuse("")
            }



        }

        holder.dataBinding?.imgAdd?.onClick {
            var num=holder.dataBinding?.tv?.text.toString().toInt()
            var i=num+1
            holder.dataBinding?.tv?.text=""+i
            item.choseNumber=""+i
            if(i>0){
                holder.dataBinding?.imgAdd?.setImageResource(R.drawable.me_add_to)

            }
            if(null!=choseData){
                choseData.onRestuse("")
            }


        }

    }
}
